package org.example.feign.fallback;

import lombok.extern.slf4j.Slf4j;
import org.example.feign.client.UserClient;
import org.example.pojo.Product;
import org.example.pojo.UserVo;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.List;

/***
 * 通过工厂，提供熔断，可以捕获异常
 */
@Component
@Slf4j
public class UserClientFallbackFactory implements FallbackFactory<UserClient> {
    @Override
    public UserClient create(Throwable cause) {
        return new UserClient() {
            @Override
            public UserVo getUser(Integer userId) {
                /**
                 * 这里可以对异常做一些处理
                 */
                log.info("报错信息{}",cause.getMessage());
                return null;
            }

            @Override
            public List<Product> getList() {
                log.info("报错信息{}",cause.getMessage());
                return null;
            }
        };
    }
}
